import os
 
def delete_folder(path):
    try:
        if os.path.isfile(path):
            os.remove(path)
        elif os.path.isdir(path):
            os.rmdir(path)
        else:
            raise ValueError(f"无效的路径: {path}")
        print(f"成功删除文件夹 {path}")
    except OSError as e:
        print(f"删除文件夹 {path} 失败: {e}")
 
# 使用示例
delete_folder('C:\Program Files\JetBrains')